﻿using System;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;

namespace LD.Model
{
    public class TB_WIP
    {
        /// <summary>
        /// 生产数量
        /// </summary>
        public int All { get { return NG + Pass; } }
        /// <summary>
        /// Fail数量
        /// </summary>
        public int NG { get; set; }

        /// <summary>
        /// 通过数量
        /// </summary>
        public int Pass { get; set; }

        /// <summary>
        /// Fail率
        /// </summary>
        public string NgYield
        {
            get
            {
                if (Pass + NG == 0)
                    return "0%";

                var yield = (NG / (Pass + NG + 0.0)) * 100.0;
                return Math.Round(yield, 2) + "%";
            }
            
        }
        /// <summary>
        /// 通过率（产品良率）
        /// </summary>
        public string PassYield
        {
            get
            {
                if (Pass + NG == 0)
                    return "0%";
                var yield = (Pass / (Pass + NG + 0.0)) * 100.0;
                return Math.Round(yield, 2) + "%";
            }
        }
        /// <summary>
        /// 近100良率
        /// </summary>
        public string Pass100Yield
        {
            get
            {
                var last100Screws = DBHelper.Instance.Sql.Queryable<TB_Screw>()
                                   .OrderByDescending(x => x.CreateTime)
                                   .Take(100)
                                   .ToList();

                var okCount = last100Screws.Count(x => x.Accumulative_Result == "OK");
                double yield = (double)okCount / (last100Screws.Count + 0.0) * 100.0;

                return Math.Round(yield, 2)+"%";
            }
        }

        /// <summary>
        /// 螺丝CT
        /// </summary>
        public double CT { get; set; }

        /// <summary>
        /// 所有螺丝抛料数量
        /// </summary>
        public int Screw_Paoliao { get; set; }

        /// <summary>
        /// 所有螺丝
        /// </summary>
        public int Screw_Total { get; set; }

        /// <summary>
        /// 抛料率
        /// </summary>
        public string PaoLiaoYield
        {
            get
            {
                if (Screw_Total == 0)
                    return "0%";
                var yield = (Screw_Paoliao / (Screw_Total + 0.0)) * 100.0;
                return Math.Round(yield, 2) + "%";
            }
        }

        /// <summary>
        /// 吸嘴使用次数
        /// </summary>
        public int Nozzle { get; set; }

        /// <summary>
        /// 批头使用次数
        /// </summary>
        public int Bitbits { get; set; }

        /// <summary>
        /// 条码
        /// </summary>
        public string Barcode { get; set; }

        /// <summary>
        /// 真空报警数
        /// </summary>
        public int vacAlNum { get; set; }

        /// <summary>
        /// 真空次数
        /// </summary>
        public int vacNum { get; set; }

        /// <summary>
        /// 真空报警率
        /// </summary>
        public string vacAlRate
        {
            get
            {
                if (vacNum == 0)
                    return "0%";
                var yield = (vacNum / (vacAlNum + 0.0)) * 100.0;
                return Math.Round(yield, 2) + "%";
            }
        }


    }
}



